const sixteenStr = `0123456789abcdef`;

function tenToSixteen(num) {
  return "" + sixteenStr[Math.floor(num / 16)] + sixteenStr[Math.floor(num % 16)];
}

function sixteenToTen(str) {
  str = "" + str;
  if (str.length > 2) return 255;
  if (str.length === 1) str = str + str;
  if (str.length) return sixteenStr.indexOf(str[0].toLowerCase()) * 16 + sixteenStr.indexOf(str[1].toLowerCase());
  return 0;
}
function parseSixTeenColor(color = "") {
  let r;
  let g;
  let b;
  color = color.replace(/^#/, "");
  if (/[^0-9a-fA-F]/.test(color)) color = `fff`;
  if (color.length <= 3) {
    r = color[0] || `f`;
    g = color[1] || `f`;
    b = color[2] || `f`;
  } else {
    r = color.slice(0, 2) || `ff`;
    g = color.slice(2, 4) || `ff`;
    b = color.slice(4, 6) || `ff`;
  }
  return `rgba(${sixteenToTen(r)}, ${sixteenToTen(g)}, ${sixteenToTen(b)}, 1)`;
}
export default {
  parseSixTeenColor,
  tenToSixteen,
  sixteenToTen,
}
